package Aug7;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

class Student implements Comparable<Student>
	{
	private Integer roll;
	private String name;
	private String address;
	
	public Student()
		{
		Scanner in = new Scanner(System.in);
		System.out.println("Enter Roll");
		roll = in.nextInt();
		System.out.println("Enter Name");
		name = in.next();
		System.out.println("Enter Address");
		address = in.next();
		}
	
	Integer getRoll()
		{
		return this.roll;
		}
	
	String getName()
		{
		return this.name;
		}
	
	String getAddress()
		{
		return this.address;
		}
	public String toString()
		{
		return this.name;
		}
	
	public int compareTo(Student s)
		{
		return this.getAddress().compareTo(s.getAddress());
		}
	}

class SortRoll implements Comparator<Student>
	{
	public int compare(Student s1, Student s2)
		{
		return s1.getRoll().compareTo(s2.getRoll());
		}
	}

class SortName implements Comparator<Student>
	{
	public int compare(Student s1, Student s2)
		{
		return s1.getName().compareTo(s2.getName());
		}
	}

class SortAddress implements Comparator<Student>
	{
	public int compare(Student s1, Student s2)
		{
		return s1.getAddress().compareTo(s2.getAddress());
		}
	}

public class CompareDemo 
	{
	public static void main(String[] args) 
		{
		ArrayList<Student> sArray = new ArrayList<Student>();
		sArray.add(new Student());
		sArray.add(new Student());
		sArray.add(new Student());
		System.out.println("Unsorted Array List : " + sArray);
		SortRoll sr = new SortRoll();
		Collections.sort(sArray,sr);
		System.out.println("Sorted Array List(According to Roll) : " + sArray);
		SortName sn = new SortName();
		Collections.sort(sArray,sn);
		System.out.println("Sorted Array List(According to Name) : " + sArray);
		SortAddress sa = new SortAddress();
		Collections.sort(sArray,sa);
		System.out.println("Sorted Array List(According to Address) : " + sArray);
		}
	}
